package com.ruoyi.smart.controller;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.smart.service.DeviceDashboardService;
import org.springframework.web.bind.annotation.*;

/**
 * 设备看板接口
 */
@RestController
@RequestMapping("/smart/device/dashboard")
public class DeviceDashboardController extends BaseController {

    private final DeviceDashboardService deviceDashboardService;

    public DeviceDashboardController(DeviceDashboardService deviceDashboardService) {
        this.deviceDashboardService = deviceDashboardService;
    }

    /**
     * 获取设备看板数据
     */
    @GetMapping("/data")
    public AjaxResult getDashboardData() {
        return AjaxResult.success(deviceDashboardService.getDashboardData());
    }

    /**
     * 获取设备实时状态流
     */
    @GetMapping("/stream")
    public AjaxResult getDeviceStatusStream() {
        return AjaxResult.success(deviceDashboardService.getDeviceStatusStream());
    }

    /**
     * 获取设备历史状态
     */
    @GetMapping("/history/{deviceId}")
    public AjaxResult getDeviceHistory(@PathVariable String deviceId,
                                       @RequestParam(defaultValue = "24") int hours) {
        return AjaxResult.success(deviceDashboardService.getDeviceHistory(deviceId, hours));
    }
}
